﻿using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Cms.Web.UI;
using Telerik.Framework.Search;

namespace SelArom.Net.Sitefinity.IndexProviders.Events
{
    public class SettingsControl : CompositeControl, ISettingsControl
    {
        #region Properties

        public string ControlTemplatePath
        {
            get
            {
                object o = this.ViewState["ControlTemplatePath"];
                //if (o == null)
                //    return "~/Sitefinity/Admin/ControlTemplates/CustomIndexSettingsControl.ascx";
                return (string)o;
            }
            set
            {
                this.ViewState["ControlTemplatePath"] = value;
            }
        }

        public IDictionary<string, string> GetSettings()
        {
            this.settings = new Dictionary<string, string>();
            return this.settings;
        }

        #endregion

        #region Methods

        protected override void CreateChildControls()
        {
            this.ctrlContainer = new Container(this);
            this.controlTemplate = new DefaultTemplate(this.settings);
            this.controlTemplate.InstantiateIn(this.ctrlContainer);
            this.Controls.Add(this.ctrlContainer);
        }

        public void InitSettings(IDictionary<string, string> settings)
        {
            this.settings = settings;
        }

        #endregion

        #region Default Template

        protected class DefaultTemplate : ITemplate
        {
            public DefaultTemplate(IDictionary<string, string> settings)
            {
                this.settings = settings;
            }

            public void InstantiateIn(Control container)
            {
            }

            private IDictionary<string, string> settings;
        }

        #endregion

        #region Container

        protected class Container : GenericContainer<SettingsControl>
        {
            public Container(SettingsControl owner)
                : base
                (owner)
            {
            }
        }

        #endregion

        #region Private Fields

        private IDictionary<string, string> settings;
        private Container ctrlContainer;
        private ITemplate controlTemplate;

        #endregion
    }
}